﻿@model RTW.OA.Models.sys_menu
@{

    Layout = "~/Views/Shared/_LayoutBase.cshtml";
}

@section styles{

}
<div id="dMain">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="ibox" style="margin-bottom: 0px;">
            <div class="ibox-title">
                <h4>@ViewBag.Title </h4>
            </div>
            <div class="ibox-content">
                @using (Html.BeginForm("Edit", "SysMenu", FormMethod.Post, new { area = "System", id = "menufrom", name = "menufrom" }))
                {
                    @Html.AntiForgeryToken()
                    @Html.HiddenFor(m=>m.MENU_ID)
                    <div class="from-content">
                        <dl>
                            <dt>菜单父级菜单</dt>
                            <dd>
                                <div class="rule-single-select">
                                    @Html.DropDownListFor(model => model.PARENT_ID, ViewBag.TreeData as List<SelectListItem>, new { @Class = "form-control", datatype = "*", sucmsg = " " })
                                </div>
                            </dd>
                        </dl>
                        <dl>
                            <dt>菜单名称</dt>
                            <dd>

                                @Html.EditorFor(model => model.MENU_NAME, new { htmlAttributes = new { @class = "input normal form-control", datatype = "*2-100", sucmsg = " " } })
                            </dd>
                        </dl>
                        <dl>
                            <dt>菜单代码</dt>
                            <dd>
                                @Html.EditorFor(model => model.MENU_CODE, new { htmlAttributes = new { @class = "input normal form-control", datatype = "*2-100", sucmsg = " " } })
                            </dd>
                        </dl>
                        <dl>
                            <dt>图标样式</dt>
                            <dd>
                                @Html.EditorFor(model => model.IMAGE, new { htmlAttributes = new { @class = "input normal form-control" } })
                            </dd>
                        </dl>
                        <dl>
                            <dt>链接路径</dt>
                            <dd>
                                @Html.EditorFor(model => model.NAVIGATE_URL, new { htmlAttributes = new { @class = "input normal form-control" } })
                            </dd>
                        </dl>
                        <dl>
                            <dt>系统菜单</dt>
                            <dd>
                                <div class="rule-single-checkbox">
                                    @Html.CheckBoxFor(m=>m.IS_SYS,  new { @class = "form-control"})
                                </div>
                            </dd>
                        </dl>
                        <dl>
                            <dt>排序号</dt>
                            <dd>
                                @Html.EditorFor(model => model.SORT, new { htmlAttributes = new { Class = "input small form-control", datatype = "n", sucmsg = " ", value = "0" } })
                            </dd>
                        </dl>
                        <dl>
                            <dt>状态</dt>
                            <dd>
                                <div class="rule-single-checkbox">
                                    @Html.CheckBoxFor(m => m.STATUS, new { @class = "form-control" }) 
                                </div>
                            </dd>
                        </dl>
                        <dl>
                            <dt>层级</dt>
                            <dd>
                                @Html.EditorFor(model => model.LEVEL, new { htmlAttributes = new { Class = "input small form-control", datatype = "n", sucmsg = " ", value = "0" } })
                            </dd>
                        </dl>
                        <dl>
                            <dt>权限按钮</dt>
                            <dd>
                                <div class="actionlist btn-toolbar">
                                </div>

                                <a class="btn btn-xs btn-primary btn-info" onclick="addaction(@Model.MENU_ID)" style="margin-top: 10px;"><i class="iconfont icon-tianjia"></i>&nbsp; 添加权限按钮</a>
                            </dd>
                        </dl>
                    </div>
                    <div class="from-footer">
                        <div class="btn-wrap" style="position: fixed;" onclick="savefrom()">
                            <a class="btn btn-sm btn-primary radius">
                                <i class="iconfont icon-save"></i>
                                提交保存
                            </a>
                            <a class="btn btn-sm btn-warning radius" onclick="parent.closeTab('6202')">
                                <i class="iconfont icon-fanhui"></i>
                                取消关闭
                            </a>
                        </div>
                    </div>
                }
            </div>
        </div>
    </div>
</div>
@section scripts{
    <script src="@Url.Content("~/Content/JS/common/WdatePicker/WdatePicker.js")"></script>
    <script type="text/javascript" charset="utf-8" src="@Url.Content("~/Content/JS/common/jquery/Validform_v5.3.2_min.js")"></script>
    <script type="text/javascript" charset="utf-8" src="@Url.Content("~/Content/JS/common/artdialog/dialog-plus-min.js")"></script>
    <script type="text/javascript" charset="utf-8" src="@Url.Content("~/Content/JS/common/webuploader/webuploader.min.js")"></script>
    <script type="text/javascript" charset="utf-8" src="@Url.Content("~/Content/editor/ueditor.config.js")"></script>
    <script type="text/javascript" charset="utf-8" src="@Url.Content("~/Content/editor/ueditor.all.min.js")"></script>
    <script type="text/javascript" charset="utf-8" src="@Url.Content("~/Content/editor/lang/zh-cn/zh-cn.js")"></script>
    @*<script type="text/javascript" charset="utf-8" src="../js/uploader.js"></script>*@

    <script src="@Url.Content("~/Content/JS/common/from.js")"></script>
    <script>
        $(function () {
            //初始化表单验证
            $("#menufrom").initValidform();

            GetPermission(@Model.MENU_ID);

        });
        function savefrom() {
            $("#menufrom").submit();
        }
        function GetPermission(id) {
            if (id != null) {
                var url = '@Url.Action("GetPermissions", "SysMenu", new { area = "System" })\/' + id;

                $.getJSON(url, function (data) {
                    var html = "";
                    if (data != null) {
                        $.each(data, function (i, item) {
                            var icon = "";
                            if (item.TYPE == 1)
                                icon = '<i class="iconfont icon-lianjie"></i>';
                            if (item.TYPE == 2)
                                icon = '<i class="iconfont icon-function"></i>';
                            if (item.TYPE == 3)
                                icon = '<i class="iconfont icon-anniu"></i>';
                            //<a class="btn btn-warning btn-xs btn-outline" onclick="parent.createTab('6202','编辑菜单','/System/SysMenu/Edit/1')">编辑</a>
                            html += `<a class="btn btn-default btn-xs" href="#"  role="button" onclick="delaction(${item.PERMISSION_ID})">${icon}${item.PERMISSION_NAME}</a>`;
                        });
                        $(".actionlist").html(html);
                    }
                });
            }
            }

            function addaction(id) {
                layer.open({
                    type: 2,
                    shadeClose: true,
                    shade: 0.8,
                    skin: 'layui-layer-rim', //加上边框
                    area: ['80%', '90%'], //宽高
                    content: '@Url.Action("AddAction", "SysMenu", new { area = "System" })\/' + id
                });
        }

        function delaction(id) {
            layer.confirm('是否删除此权限？', {
                btn: ['确定', '取消'] //按钮
            }, function () {
                var url = '@Url.Action("DeleteAction", "SysMenu", new { area = "System" })\/' + id;
                $.get(url, function (result) {
                    GetPermission(@Model.MENU_ID);
                    layer.msg('删除权限成功！',{ icon: 1,
                        time: 2000//2s后自动关闭
                    });
                });
            }, function () {

            });
        }
    </script>

}